package com.icode.web.controller.house;

import com.icode.core.dto.house.MyHouseDTO;

import com.icode.core.dto.manager.AssignmentDTO;
import com.icode.core.model.user.User;
import com.icode.core.shared.SecurityUtil;
import com.icode.service.house.MyHouseService;
import com.icode.service.management.AssignmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: lb
 * Date: 15-11-26
 * Time: 下午3:18
 * To change this template use File | Settings | File Templates.
 */
@Controller("ToAssignmnetController")
@RequestMapping("/toAssignmnet")
public class ToAssignmnetController {
    @Autowired
    private MyHouseService myHouseService;
    @Autowired
    private AssignmentService assignmentService;

    @RequestMapping(value = "list", method = RequestMethod.GET)
    private String showMyHouseList(Model model) {
      //  List<MyHouseDTO> toAssignmnetHouse = myHouseService.findMyHouseisToAssignmnet();
        List<AssignmentDTO> assignmentDTOs = assignmentService.getAssignments("TOASSIGNMNET");
      //  model.addAttribute("myHouseDTOs", toAssignmnetHouse);
        model.addAttribute("assignmentDTOs", assignmentDTOs);
        return "front/toassignmnet/toAssigmnentList";
    }

    @RequestMapping(value = "details/{myHouseGuid}", method = RequestMethod.GET)
    private String showdetails(@PathVariable String myHouseGuid,Model model) {
        MyHouseDTO toAssignmnetHouse = myHouseService.findMyHouseByGuid(myHouseGuid);
        model.addAttribute("myHouseDTO", toAssignmnetHouse);
        return "front/toassignmnet/toAssigmnentDetails";
    }

    @RequestMapping(value = "search", method = RequestMethod.POST)
        public String search(String area, String week, String themes,  Model model) {
        List<MyHouseDTO> toAssignmnetHouse = myHouseService.findMyHouseByCondition(area, week, themes);
        model.addAttribute("myHouseDTOs", toAssignmnetHouse);
        return "front/toassignmnet/toAssigmnentListdata";
    }

    @RequestMapping(value = "assignmnet/{myhouseguid}", method = RequestMethod.GET)
    public String assignmnet(@PathVariable String myhouseguid) {
        User user = SecurityUtil.currentUser();
        assignmentService.setAssignmentsByMyHouseGuid(myhouseguid,user);
        return "/toAssignmnet/list";
    }
}
